using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace CodePlex.Resourceful
{
    public abstract class TracerListener
    {

        abstract public void WriteLine(string value);

        abstract public void Write(string value);


        public static TracerListener From(TextWriter writer)
        {
            return new TextWriterTracerListener(writer);
        }

        public static TracerListener From(Tracer tracer)
        {
            return new ForwardingTracerListener(tracer);
        }




        private class ForwardingTracerListener : TracerListener
        {

            private readonly Tracer _tracer;

            public ForwardingTracerListener(Tracer tracer)
            {
                _tracer = tracer;
            }

            public override void WriteLine(string value)
            {
                _tracer.WriteLine(value);
            }

            public override void Write(string value)
            {
                _tracer.Write(value);
            }
        }

        private class TextWriterTracerListener : TracerListener
        {

            private readonly TextWriter _writer;

            public TextWriterTracerListener(TextWriter writer)
            {
                _writer = writer;
            }

            public override void WriteLine(string value)
            {
                _writer.WriteLine(value);
            }

            public override void Write(string value)
            {
                _writer.Write(value);
            }
        }

       
    }
}
